﻿using System;
using System.IO;
using System.Data;
using System.Text;
using System.Configuration;
using System.Collections.Generic;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Resources;
using System.Globalization;

using CE.Mail;
using CE.User;
using CE.Global;
using CE.Security;
using CE.InputOut;
using CE.Database;
using CE.CarInsurance;
using CXDecryption;


public partial class carinsurance_fleet_NewFleetCar : System.Web.UI.Page
{
    CarUserAccount _account = null;
    CarUserAccountDB _accountdb = null;
    CarUserProfile _profile = null;
    CarUserProfileDB _profiledb = null;
    CarUserContact _contact = null;
    CarUserContactDB _contactdb = null;

    protected override void InitializeCulture()
    {
        String selectedCulture = CE.Global.General.SetCulture();
        base.InitializeCulture();
    }

    private DateTime dateTimeNow = CE.Global.General.GetUTCDateTime();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session[CE.Global.General.UserId] == null)
        {
            Response.Redirect("~/SiteUserSecureLogin.aspx");
        }

        if (!IsPostBack)
        {
            lblResetUrl.Text = Request.Url.ToString();
            ResetAll();
            DateTime time = dateTimeNow;
            lblStartDateTime.Text = time.ToString("dd/MMM/yyyy hh:mm:ss tt"); //Don't use HTML tag inside text
            txtAgentId.Text = Session[General.UserId].ToString();

            if (Request.QueryString["new"] != null)
            {
                txtNewQuote.Text = Request.QueryString["new"].ToString();
            }
            else
            {
                txtNewQuote.Text = string.Empty;
            }
            ResetAll();

            if (Request.QueryString["CompanyId"] != null)
            {
                txtCompanyId.Text = Request.QueryString["CompanyId"].ToString();
            }
            else
            {
                Response.Redirect("FleetCompanyList.aspx");
            } if (Request.QueryString["carid"] != null)
            {
                txtFleetCarId.Text = Request.QueryString["carid"].ToString();
            }
            else
            {
                txtFleetCarId.Text ="0";
            }

            GetCarBody();
            LoadInsuranceType();
            LoadGarageType();
            LoadCarYear();
            
            LoadDOB();
            LoadCommanceDate();
            LoadCurrentInsurer();
            ddlInsuranceType.Text = "10";
            ddlInsuranceType_SelectedIndexChanged(null, null);

            txtAgentId.Text = "0";
            if (Request.QueryString["CompanyId"] != null)
            {
                txtCompanyId.Text = Request.QueryString["CompanyId"].ToString();
                LoadCarGrid(Convert.ToInt64(txtCompanyId.Text.Trim()));
                string strSql = @"SELECT AgentId,CompanyName FROM tblFleetCompany WHERE CompanyId = " + txtCompanyId.Text.Trim();
                MyDatabase _db = new MyDatabase();
                DataTable _SelectItemResult = _db.GetDataTable(strSql);
                if (_SelectItemResult != null && _SelectItemResult.Rows.Count > 0)
                {
                    if (_SelectItemResult.Rows[0]["AgentId"] != DBNull.Value)
                    {
                        txtAgentId.Text = _SelectItemResult.Rows[0]["AgentId"].ToString();
                    }
                    if (_SelectItemResult.Rows[0]["CompanyName"] != DBNull.Value)
                    {
                        lblPageName.Text += " - " + _SelectItemResult.Rows[0]["CompanyName"].ToString();
                    }
                }
            }
          
        }
    }

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        
      
        if (CheckClaimValue() == true)
        {
            Page.Validate("newfleetcar");
            if (Page.IsValid)
            {
                
                Int64 _CompanyId = 0;
              

                if (!Int64.TryParse(txtCompanyId.Text, out  _CompanyId))
                {
                    _CompanyId = 0;
                }

               
                if (_CompanyId > 0)
                {

                    if (Save(_CompanyId))
                    {
                        ClearAllList();
                        ClearFields();
                        LoadCarGrid(Convert.ToInt64(txtCompanyId.Text.Trim()));
                        ddlCarMake_SelectedIndexChanged(null, null);
                        txtOtherCarMake.Text = "";
                        txtOtherCarModel.Text = "";
                        ddlOtherCarBody.SelectedIndex = 0;
                        ddlOtherCarDoor.SelectedIndex = 0;
                        txtCcCar.Text = "";
                        divOtherCar.Style.Add("display", "none");
                        lblMessage.Text = "Saved successfully!";
                    }
                    else
                    {
                        lblMessage.Text = "Saving did NOT succeed!";
                    }
                }
                else
                {
                    lblMessage.Text = "Please fill all require fields completly and correctly.";
                }
            }
        }
        else
        {
            lblMessage.Text = "Please fill claim value correctly.";
        }

    }

    protected void btnReset_Click(object sender, EventArgs e)
    {
        Response.Redirect(lblResetUrl.Text.ToString());
    }

    protected void btnCompany_Click(object sender, EventArgs e)
    {
        Response.Redirect("FleetCompanyList.aspx?CompanyId=" + txtCompanyId.Text.Trim());
    }

    protected void btnNewCar_Click(object sender, EventArgs e)
    {
        ClearAllList();
        ClearFields();
    }

    protected void btnQuote_Click(object sender, EventArgs e)
    {
        string _strParameters = "CompanyId=" + txtCompanyId.Text.Trim();
        Response.Redirect("FleetManualQuote.aspx?" + _strParameters.ToString());
    }

    #region Dropdown List

    protected void ddlInsuranceType_SelectedIndexChanged(object sender, EventArgs e)
    {
        try
        {
            LoadCarYear();
            if (ddlInsuranceType.Text == "10")
            {
                ddlGarageType.Enabled = true;
                rowGarageType.Visible = true;
                ddlCTPL.Enabled = false;
                ddlModification.Enabled = true;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = true;
                ddlProvinceRegistration.Enabled = true;
                ddlAnyClaim.Enabled = true;
                ddlNCB.Enabled = true;
                ddlNamedDrivers.Enabled = true;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else if (ddlInsuranceType.Text == "11")
            {
                ddlGarageType.Enabled = true;
                rowGarageType.Visible = true;
                ddlCTPL.Enabled = false;
                ddlModification.Enabled = false;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = false;
                ddlProvinceRegistration.Enabled = false;
                ddlAnyClaim.Enabled = false;
                ddlNCB.Enabled = false;
                ddlNamedDrivers.Enabled = false;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else if (ddlInsuranceType.Text == "21")
            {
                ddlGarageType.Enabled = true;
                rowGarageType.Visible = true;
                ddlCTPL.Enabled = false;
                ddlModification.Enabled = false;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = true;
                ddlProvinceRegistration.Enabled = false;
                ddlAnyClaim.Enabled = false;
                ddlNCB.Enabled = false;
                ddlNamedDrivers.Enabled = false;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else if (ddlInsuranceType.Text == "31")
            {
                ddlGarageType.Enabled = true;
                rowGarageType.Visible = true;
                ddlCTPL.Enabled = false;
                ddlModification.Enabled = false;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = true;
                ddlProvinceRegistration.Enabled = false;
                ddlAnyClaim.Enabled = false;
                ddlNCB.Enabled = false;
                ddlNamedDrivers.Enabled = false;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else if (ddlInsuranceType.Text == "30")
            {
                ddlGarageType.Enabled = false;
                rowGarageType.Visible = false;
                ddlCTPL.Enabled = true;
                ddlModification.Enabled = false;
                txtAccModAmount.Enabled = false;
                ddlDeduct.Enabled = true;
                ddlProvinceRegistration.Enabled = false;
                ddlAnyClaim.Enabled = false;
                ddlNCB.Enabled = false;
                ddlNamedDrivers.Enabled = false;
                ddlDriver1DOBDay.Enabled = false;
                ddlDriver1DOBMonth.Enabled = false;
                ddlDriver1DOBYear.Enabled = false;
                ddlDriver2DOBDay.Enabled = false;
                ddlDriver2DOBMonth.Enabled = false;
                ddlDriver2DOBYear.Enabled = false;

                ddlGarageType.SelectedIndex = 0;
                ddlCarYear.SelectedIndex = 0;
                ddlCarYear_SelectedIndexChanged(null, null);
                ddlCTPL.SelectedIndex = 0;
                ddlModification.SelectedIndex = 0;
                ddlModification_SelectedIndexChanged(null, null);
                txtAccModAmount.Text = "";
                ddlDeduct.SelectedIndex = 0;
                ddlProvinceRegistration.SelectedIndex = 0;
                ddlAnyClaim.SelectedIndex = 0;
                ddlNCB.SelectedIndex = 0;
                ddlNamedDrivers.SelectedIndex = 0;
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlDriver1DOBDay.SelectedIndex = 0;
                ddlDriver1DOBMonth.SelectedIndex = 0;
                ddlDriver1DOBYear.SelectedIndex = 0;
                ddlDriver2DOBDay.SelectedIndex = 0;
                ddlDriver2DOBMonth.SelectedIndex = 0;
                ddlDriver2DOBYear.SelectedIndex = 0;
            }
            else
            {
                //pnlDetails.Visible = false;
            }
            ValidateControlEnable();
            setControlVisible();
        }
        catch
        {

        }
    }


   

    protected void ddlCarYear_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCarYear.Text == "-1")
        {
            ClearAllList();
        }
        else
        {
            GetCarMakeList(ddlCarYear.Text, ddlCarMake);
            if (ddlCarMake.Items.Count > 0)
            {
                ddlCarMake.SelectedIndex = 0;
                ddlCarMake_SelectedIndexChanged(sender, e);
            }
        }
    }

    protected void ddlCarMake_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCarMake.Text == "-1")
        {
            ddlModelBodyCCDoor.Items.Clear();
            ddlModelBodyCCDoor.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
            txtSumInsured.Text = "0";
            lblSumInsured.Text = "0";
            txtGroupNo.Text = "-1";
        }
        else
        {
            GetCarModelDescList(ddlCarMake.Text, ddlCarYear.Text, ddlModelBodyCCDoor);
            if (ddlModelBodyCCDoor.Items.Count > 0)
            {
                ddlModelBodyCCDoor.SelectedIndex = 0;
                ddlModelBodyCCDoor_SelectedIndexChanged(sender, e);
            }
        }
    }

    protected void ddlModelBodyCCDoor_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlCarYear.SelectedIndex >= 0 && ddlCarMake.SelectedIndex >= 0 & ddlModelBodyCCDoor.SelectedIndex >= 0)
        {
            string[] _tempDesc = ddlModelBodyCCDoor.Text.Split(' ');
            string _model = "";
            string _body = "";
            string _cc = "";
            string _door = "";
            if (_tempDesc.Length == 5)
            {
                _model = _tempDesc[0];
                _body = _tempDesc[1];
                _cc = _tempDesc[2].Substring(0, _tempDesc[2].Length - 2);
                _door = _tempDesc[3];
            }
            else if (_tempDesc.Length == 6)
            {
                _model = _tempDesc[0] + " " + _tempDesc[1];
                _body = _tempDesc[2];
                _cc = _tempDesc[3].Substring(0, _tempDesc[3].Length - 2);
                _door = _tempDesc[4];
            }
            else if (_tempDesc.Length == 7)
            {
                _model = _tempDesc[0] + " " + _tempDesc[1] + " " + _tempDesc[2];
                _body = _tempDesc[3];
                _cc = _tempDesc[4].Substring(0, _tempDesc[4].Length - 2);
                _door = _tempDesc[5];
            }
            lblModelDesc.Text = "model : " + _model + ", body: " + _body + ", cc: " + _cc + ", door: " + _door;
            GetCarModelSumInsuredAmountAndVehicleType(ddlCarMake.Text, _model, _body, _cc, _door, ddlCarYear.Text, txtSumInsured, lblSumInsured, lblCarVehicleType);
            txtNewSumInsured.Text = txtSumInsured.Text;
            if (ddlModification.Text == "1")
            {
                if (txtAccModAmount.Text.Length > 0)
                {
                    int _sumInsured = Convert.ToInt32(txtSumInsured.Text);
                    int _tmpAmount = 0;
                    if (Int32.TryParse(txtAccModAmount.Text, out _tmpAmount))
                    {
                        _sumInsured += _tmpAmount;
                        txtNewSumInsured.Text = _sumInsured.ToString();
                        lblSumInsured.Text = Convert.ToInt32(txtNewSumInsured.Text).ToString("#,000");
                    }
                    else
                    {
                        txtNewSumInsured.Text = _sumInsured.ToString();
                        txtAccModAmount.Text = "";
                    }
                }
            }
            if (ddlModelBodyCCDoor.Text != "-2")
            {
                GetCarModelGroupNo(ddlCarMake.Text, _model, _body, _cc, _door, txtGroupNo);
            }
            else
            {
                txtGroupNo.Text = "0";
            }
        }
    }

    protected void ddlModification_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlModification.Text == "1")
        {
            //divModificationCost.Visible = true;
            txtAccModAmount.Enabled = true;
            rfvAccModAmount.Enabled = true;
            revAccModAmount.Enabled = true;
        }
        else
        {
            //divModificationCost.Visible = false;
            txtAccModAmount.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
        }
        setControlVisible();
    }

    protected void ddlAnyClaim_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlAnyClaim.Text == "1")
        {
            ddlNCB.Items.Clear();
            ddlNCB.Items.Add(new ListItem("No NCD", "0"));
        }
        else
        {
            ddlNCB.Items.Clear();
            ddlNCB.Items.Add(new ListItem(Resources.General.Select, "-1"));
            ddlNCB.Items.Add(new ListItem("0 %", "0"));
            ddlNCB.Items.Add(new ListItem("20 %", "20"));
            ddlNCB.Items.Add(new ListItem("30 %", "30"));
            ddlNCB.Items.Add(new ListItem("40 %", "40"));
            ddlNCB.Items.Add(new ListItem("50 %", "50"));
        }
    }

    protected void ddlNamedDrivers_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (ddlNamedDrivers.Text == "1")
        {
            //divDriver1.Visible = true;
            //divDriver2.Visible = false;  
            ddlDriver1DOBDay.Enabled = true;
            ddlDriver1DOBMonth.Enabled = true;
            ddlDriver1DOBYear.Enabled = true;
            ddlDriver2DOBDay.Enabled = false;
            ddlDriver2DOBMonth.Enabled = false;
            ddlDriver2DOBYear.Enabled = false;

            rfvDriver1DOBDay.Enabled = true;
            rfvDriver1DOBMonth.Enabled = true;
            rfvDriver1DOBYear.Enabled = true;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
        }
        else if (ddlNamedDrivers.Text == "2")
        {
            //divDriver1.Visible = true;
            //divDriver2.Visible = true;
            ddlDriver1DOBDay.Enabled = true;
            ddlDriver1DOBMonth.Enabled = true;
            ddlDriver1DOBYear.Enabled = true;
            ddlDriver2DOBDay.Enabled = true;
            ddlDriver2DOBMonth.Enabled = true;
            ddlDriver2DOBYear.Enabled = true;

            rfvDriver1DOBDay.Enabled = true;
            rfvDriver1DOBMonth.Enabled = true;
            rfvDriver1DOBYear.Enabled = true;
            rfvDriver2DOBDay.Enabled = true;
            rfvDriver2DOBMonth.Enabled = true;
            rfvDriver2DOBYear.Enabled = true;
        }
        else
        {
            //divDriver1.Visible = false;
            //divDriver2.Visible = false;
            ddlDriver1DOBDay.Enabled = false;
            ddlDriver1DOBMonth.Enabled = false;
            ddlDriver1DOBYear.Enabled = false;
            ddlDriver2DOBDay.Enabled = false;
            ddlDriver2DOBMonth.Enabled = false;
            ddlDriver2DOBYear.Enabled = false;

            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
        }
        setControlVisible();
    }

    #endregion

    protected void grvFleetCar_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (grvFleetCar.Rows.Count > 0)
        {
            Int64 CompanyId = 0;
            Int64 FleetCarId = 0;
            txtFleetCarId.Text = grvFleetCar.SelectedDataKey[1].ToString();
            txtFleetCarPolicyId.Text = grvFleetCar.SelectedDataKey[2].ToString();
            CompanyId = Convert.ToInt64(txtCompanyId.Text.Trim());
            FleetCarId = Convert.ToInt64(txtFleetCarId.Text.Trim());
            //GetSelectCarDetail(CompanyId, FleetCarId);
            FleetCarDetail _fleetcardetail = new FleetCarDetail();
            FleetCarDetailDB _fleetcardetaildb = new FleetCarDetailDB();
            FleetCarPolicy _fleetcarpolicy = new FleetCarPolicy();
            FleetCarPolicyDB _fleetcarpolicydb = new FleetCarPolicyDB();
            _fleetcardetail = _fleetcardetaildb.GetCar(FleetCarId, CompanyId);
            _fleetcarpolicy = _fleetcarpolicydb.GetCarPolicy(FleetCarId, CompanyId);
            if (_fleetcardetail != null && _fleetcarpolicy != null)
            {
                SetProperty(_fleetcardetail, _fleetcarpolicy);
            }
            _fleetcardetail = null;
            _fleetcardetaildb = null;
            _fleetcarpolicy = null;
            _fleetcarpolicydb = null;
        }
    }

    protected void grvFleetCar_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName.Equals("MyQuote"))
        {
            if (e.CommandArgument != null)
            {
                Response.Redirect("FleetManualQuote.aspx?CompanyId=" + txtCompanyId.Text.Trim() + "&FleetCarId=" + e.CommandArgument.ToString());
            }
        }
        
    }

    private void LoadCarGrid(Int64 CompanyId)
    {
        DataSet _dsFleetCar = new DataSet();
        MyDatabase _db = new MyDatabase();
        string _spName = "sprocFleetCarAndPolicyDetailSelectItemList";
        SortedList _spPara = new SortedList();
        _spPara.Add("@CompanyId", CompanyId);
        _dsFleetCar = _db.GetDataSet(_spName, _spPara);
        if (_dsFleetCar != null && _dsFleetCar.Tables.Count > 0)
        {
            grvFleetCar.DataSource = _dsFleetCar.Tables[0];
            grvFleetCar.DataBind();
        }
        else
        {
            grvFleetCar.DataSource = null;
            grvFleetCar.DataBind();
        }
    }
    
    private void SetProperty(FleetCarDetail _FleetCarDetail, FleetCarPolicy _FleetCarPolicy)
    {
        try
        {
            CultureInfo ci = new CultureInfo("th-TH");
            if (lblLangOption.Text == "2")
            {
                ci = new CultureInfo("en-US");
            }

            ddlInsuranceType.Text = _FleetCarPolicy.InsuranceType.ToString();
            ddlInsuranceType_SelectedIndexChanged(null, null);
            ddlGarageType.Text = _FleetCarPolicy.GarageType.ToString();
            LoadCarYear();
            ddlCarYear.Text = _FleetCarDetail.ManufactYear.ToString();
            ddlCarYear_SelectedIndexChanged(null, null);
            ddlCurrentInsurer.Text = _FleetCarDetail.Info1;

            if (_FleetCarDetail != null && _FleetCarDetail.Status == true)
            {
                if (!_FleetCarDetail.BInfo1)
                {
                    ddlCarMake.Text = _FleetCarDetail.CarMakeName;
                    ddlCarMake_SelectedIndexChanged(null, null);
                    if (ddlCarMake.SelectedIndex >= 0)
                    {
                        string _tempDesc = _FleetCarDetail.CarModelName + " " + _FleetCarDetail.Body + " " + _FleetCarDetail.CC + "cc " + _FleetCarDetail.Door.ToString() + " doors";

                        ddlModelBodyCCDoor.Text = _tempDesc;
                        ddlModelBodyCCDoor_SelectedIndexChanged(null, null);
                    }
                }
                else
                {
                    ddlCarMake.Text = "-2";
                    ddlCarMake_SelectedIndexChanged(null, null);
                    ddlModelBodyCCDoor.Text = "-2";
                    ddlModelBodyCCDoor_SelectedIndexChanged(null, null);
                    string[] carmakename = _FleetCarDetail.MakeModelDesc.Split(' ');
                    txtOtherCarMake.Text = (carmakename.Length > 1 ? carmakename[0] : _FleetCarDetail.CarMakeName);
                    txtOtherCarModel.Text = _FleetCarDetail.CarModelName;
                    ddlOtherCarBody.Text = _FleetCarDetail.Body;
                    txtCcCar.Text = _FleetCarDetail.CC.ToString();
                    ddlOtherCarDoor.Text = _FleetCarDetail.Door.ToString();
                }
                txtGroupNo.Text = _FleetCarDetail.GroupNo.ToString();
                lblCarVehicleType.Text = _FleetCarDetail.Info2;
                if (_FleetCarDetail.Info3 == "110" || _FleetCarDetail.Info3 == "210" || _FleetCarDetail.Info3 == "320")
                {
                    ddlVehicleType.Text = "110";
                }
                else
                {
                    ddlVehicleType.Text = "120";
                }
                //ddlVehicleType_SelectedIndexChanged(null, null);
                txtSumInsured.Text = _FleetCarPolicy.SumInsured.ToString();
                lblSumInsured.Text = Convert.ToInt32(txtSumInsured.Text).ToString("#,000");
                ddlModification.Text = Convert.ToInt16(_FleetCarPolicy.IsAddAccMod).ToString();
                if (ddlModification.Text == "1")
                {
                    txtNewSumInsured.Text = (_FleetCarPolicy.SumInsured + _FleetCarPolicy.AddAccModAmount).ToString();
                    txtAccModAmount.Text = _FleetCarPolicy.AddAccModAmount.ToString();
                    lblSumInsured.Text = Convert.ToInt32(txtNewSumInsured.Text).ToString("#,000");
                }
                ddlDeduct.SelectedValue = Convert.ToInt32(_FleetCarPolicy.Deductible) == 0 ? "0" : "-1";
                ddlProvinceRegistration.Text = _FleetCarPolicy.ProvinceRegistration;
                lblTESCO200.Text = _FleetCarPolicy.Info8.ToUpper();

                LoadCommanceDate(_FleetCarPolicy.CoverageCommenceDate);

                ddlCoverageComDate.Text = _FleetCarPolicy.CoverageCommenceDate.Day.ToString("00") + _FleetCarPolicy.CoverageCommenceDate.Month.ToString("00") + _FleetCarPolicy.CoverageCommenceDate.Year.ToString("0000");
                DateTime _dtCommDate = _FleetCarPolicy.CoverageCommenceDate;
                _dtCommDate = _dtCommDate.AddDays(-1);
                _dtCommDate = _dtCommDate.AddYears(1);
                lblCoverageExpireDate.Text = _dtCommDate.ToString("dd/MMMM/yyyy", ci);
                ddlAnyClaim.Text = Convert.ToInt16(_FleetCarPolicy.IsClaimLastYear).ToString();
                ddlNamedDrivers.Text = _FleetCarPolicy.NoOfDriver.ToString();
                ddlNamedDrivers_SelectedIndexChanged(null, null);
                ddlCTPL.Text = Convert.ToInt16(_FleetCarPolicy.IsCTPL).ToString();
                ddlNCB.Text = _FleetCarPolicy.NCDPercent.ToString();

                if (_FleetCarPolicy.Info6.Length > 0 && _FleetCarPolicy.Info7.Length > 0)
                {
                    divLastYearRefNo.Visible = true;
                    lblLastYearCarID.Text = _FleetCarPolicy.Info6;
                    lblLastYearRefNo.Text = _FleetCarPolicy.Info7;
                }

                if (_FleetCarPolicy.NoOfDriver > 0)
                {
                    DataTable _dtDriver = new DataTable();
                    FleetCarDriverDB _fleetcardriverdb = new FleetCarDriverDB();
                    _dtDriver = _fleetcardriverdb.GetCarDriverList(_FleetCarDetail.FleetCarId, _FleetCarDetail.CompanyId);
                    if (_dtDriver != null && _dtDriver.Rows.Count > 0)
                    {
                        txtDriverId1.Text = _dtDriver.Rows[0]["FleetCarDriverId"].ToString();
                        DateTime _DriverDOB1 = new DateTime();
                        DateTime.TryParse(_dtDriver.Rows[0]["DOB"].ToString(), out _DriverDOB1);
                        ddlDriver1DOBDay.Text = _DriverDOB1.Day.ToString("00");
                        ddlDriver1DOBMonth.Text = _DriverDOB1.Month.ToString("00");
                        ddlDriver1DOBYear.Text = _DriverDOB1.Year.ToString("0000");
                        if (_dtDriver != null && _dtDriver.Rows.Count > 1)
                        {
                            txtDriverId2.Text = _dtDriver.Rows[1]["FleetCarDriverId"].ToString();
                            DateTime _DriverDOB2 = new DateTime();
                            DateTime.TryParse(_dtDriver.Rows[1]["DOB"].ToString(), out _DriverDOB2);
                            ddlDriver2DOBDay.Text = _DriverDOB2.Day.ToString("00");
                            ddlDriver2DOBMonth.Text = _DriverDOB2.Month.ToString("00");
                            ddlDriver2DOBYear.Text = _DriverDOB2.Year.ToString("0000");
                        }
                    }
                }
                ValidateControlEnable();
            }
            else
            {
                ddlDeduct.Text = "-1";
                ddlCoverageComDate.Text = dateTimeNow.AddDays(45).ToString("ddMMyyyy");
                ddlProvinceRegistration.Text = "BKK";
                ddlAnyClaim.Text = "0";
                ddlAnyClaim_SelectedIndexChanged(null, null);
                ddlNCB.Text = "20";
                ddlModification.Text = "0";
                ddlModification_SelectedIndexChanged(null, null);
            }
        }
        catch (Exception ex)
        {
        }
    }

    protected void ResetAll()
    {
        txtCarId.Text = "";
        txtCECarPolicyId.Text = "";
    }

    private void ClearFields()
    {
        txtFleetCarId.Text = "0";
        txtFleetCarPolicyId.Text = "0";
        ddlGarageType.SelectedIndex = 0;
        ddlCarYear.SelectedIndex = 0;
        ddlCurrentInsurer.SelectedIndex = 0;
        ddlProvinceRegistration.SelectedIndex = 0;
        ddlModification.SelectedIndex = 0;
        ddlModification_SelectedIndexChanged(null, null);
        ddlAnyClaim.SelectedIndex = 0;
        ddlAnyClaim_SelectedIndexChanged(null, null);
        ddlNamedDrivers.SelectedIndex = 0;
        ddlNamedDrivers_SelectedIndexChanged(null, null);
        ddlCoverageComDate.SelectedIndex = 0;
        ddlDeduct.SelectedIndex = 0;
    }

    private void ClearAllList()
    {
        ddlCarMake.Items.Clear();
        ddlCarMake.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
        ddlModelBodyCCDoor.Items.Clear();
        ddlModelBodyCCDoor.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
        txtSumInsured.Text = "0";
        lblSumInsured.Text = "0";
        txtGroupNo.Text = "-1";
    }

    public void ValidateControlEnable()
    {

        if (ddlInsuranceType.Text == "10")
        {
            rfvGarageType.Enabled = true;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = false;
            rfvModification.Enabled = true;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            if (ddlModification.Text == "1")
            {
                rfvAccModAmount.Enabled = true;
                revAccModAmount.Enabled = true;
            }
            rfvProvinceRegistration.Enabled = true;
            rfvAnyClaim.Enabled = true;
            rfvNCB.Enabled = true;
            if (ddlNamedDrivers.Text == "0")
            {
                rfvDriver1DOBDay.Enabled = false;
                rfvDriver1DOBMonth.Enabled = false;
                rfvDriver1DOBYear.Enabled = false;
                rfvDriver2DOBDay.Enabled = false;
                rfvDriver2DOBMonth.Enabled = false;
                rfvDriver2DOBYear.Enabled = false;
            }
            else if (ddlNamedDrivers.Text == "1")
            {
                rfvDriver1DOBDay.Enabled = true;
                rfvDriver1DOBMonth.Enabled = true;
                rfvDriver1DOBYear.Enabled = true;
                rfvDriver2DOBDay.Enabled = false;
                rfvDriver2DOBMonth.Enabled = false;
                rfvDriver2DOBYear.Enabled = false;
            }
            else if (ddlNamedDrivers.Text == "2")
            {
                rfvDriver1DOBDay.Enabled = true;
                rfvDriver1DOBMonth.Enabled = true;
                rfvDriver1DOBYear.Enabled = true;
                rfvDriver2DOBDay.Enabled = true;
                rfvDriver2DOBMonth.Enabled = true;
                rfvDriver2DOBYear.Enabled = true;
            }
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
        }
        else if (ddlInsuranceType.Text == "11")
        {
            rfvGarageType.Enabled = true;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = false;
            rfvModification.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            rfvProvinceRegistration.Enabled = false;
            rfvAnyClaim.Enabled = false;
            rfvNCB.Enabled = false;
            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
        }
        else if (ddlInsuranceType.Text == "21")
        {
            rfvGarageType.Enabled = true;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = false;
            rfvModification.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            rfvProvinceRegistration.Enabled = false;
            rfvAnyClaim.Enabled = false;
            rfvNCB.Enabled = false;
            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
        }
        else if (ddlInsuranceType.Text == "31")
        {
            rfvGarageType.Enabled = true;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = false;
            rfvModification.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            rfvProvinceRegistration.Enabled = false;
            rfvAnyClaim.Enabled = false;
            rfvNCB.Enabled = false;
            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
        }
        else if (ddlInsuranceType.Text == "30")
        {
            rfvGarageType.Enabled = false;
            rfvCarYear.Enabled = true;
            rfvCarMake.Enabled = true;
            rfvModelBodyCCDoor.Enabled = true;
            rfvCTPL.Enabled = true;
            rfvModification.Enabled = false;
            rfvAccModAmount.Enabled = false;
            revAccModAmount.Enabled = false;
            rfvProvinceRegistration.Enabled = false;
            rfvAnyClaim.Enabled = false;
            rfvNCB.Enabled = false;
            rfvDriver1DOBDay.Enabled = false;
            rfvDriver1DOBMonth.Enabled = false;
            rfvDriver1DOBYear.Enabled = false;
            rfvDriver2DOBDay.Enabled = false;
            rfvDriver2DOBMonth.Enabled = false;
            rfvDriver2DOBYear.Enabled = false;
            rfvCoverageComDate.Enabled = true;
            rfvCurrentInsurer.Enabled = true;
        }
    }

    #region Load Control

    private void GetCarBody()
    {
        try
        {
            MyDatabase _db = new MyDatabase();
            DataTable _dt = new DataTable();
            string _splStatement = "select distinct BodyStyleDescription from tblCarVehicle where BodyStyleDescription is not null order by BodyStyleDescription";

            _dt = _db.GetDataTable(_splStatement);
            ddlOtherCarBody.Items.Clear();
            if (_dt != null && _dt.Rows.Count > 0)
            {
                ddlOtherCarBody.DataSource = _dt;
                ddlOtherCarBody.DataTextField = "BodyStyleDescription";
                ddlOtherCarBody.DataValueField = "BodyStyleDescription";
                ddlOtherCarBody.DataBind();
            }
            ddlOtherCarBody.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        }
        catch (Exception)
        {
        }
    }

    public void LoadInsuranceType()
    {
        ddlInsuranceType.Items.Clear();
        ddlInsuranceType.Items.Add(new ListItem(Resources.General.Select, "-1"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassOne, "10"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassOneLowCost, "11"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassTwoPlus, "21"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassThreePlus, "31"));
        ddlInsuranceType.Items.Add(new ListItem(Resources.CarInsurance.Insurance_ClassThree, "30"));
    }

    public void LoadGarageType()
    {
        ddlGarageType.Items.Clear();
        ddlGarageType.Items.Add(new ListItem(Resources.General.Select, "-1"));
        ddlGarageType.Items.Add(new ListItem(Resources.CarInsurance.Garage_Authorized, "1"));
        ddlGarageType.Items.Add(new ListItem(Resources.CarInsurance.Garage_Dealer, "2"));
    }



    public void LoadDate(DropDownList ddl)
    {
        string val = "";
        ddl.Items.Clear();
        ddl.Items.Add(new ListItem(Resources.CarInsurance.Day, "-1"));
        for (int _date = 1; _date <= 31; _date++)
        {
            val = _date.ToString();
            if (_date < 10)
            {
                val = "0" + _date.ToString();
            }
            ddl.Items.Add(new ListItem(val, val));
        }
    }

    public void LoadMonth(DropDownList ddl)
    {
        string val = "";
        ddl.Items.Clear();
        ddl.Items.Add(new ListItem(Resources.CarInsurance.Month, "-1"));
        string monthname = Resources.General.Select;
        for (int _month = 1; _month <= 12; _month++)
        {
            val = _month.ToString();
            if (_month < 10)
            {
                val = "0" + _month.ToString();
            }
            else
            {
                val = _month.ToString();
            }
            if (_month == 1)
            {
                monthname = Resources.MonthResource.January;
            }
            else if (_month == 2)
            {
                monthname = Resources.MonthResource.February;
            }
            else if (_month == 3)
            {
                monthname = Resources.MonthResource.March;
            }
            else if (_month == 4)
            {
                monthname = Resources.MonthResource.April;
            }
            else if (_month == 5)
            {
                monthname = Resources.MonthResource.May;
            }
            else if (_month == 6)
            {
                monthname = Resources.MonthResource.June;
            }
            else if (_month == 7)
            {
                monthname = Resources.MonthResource.July;
            }
            else if (_month == 8)
            {
                monthname = Resources.MonthResource.August;
            }
            else if (_month == 9)
            {
                monthname = Resources.MonthResource.September;
            }
            else if (_month == 10)
            {
                monthname = Resources.MonthResource.October;
            }
            else if (_month == 11)
            {
                monthname = Resources.MonthResource.November;
            }
            else if (_month == 12)
            {
                monthname = Resources.MonthResource.December;
            }
            //ddl.Items.Clear();
            ddl.Items.Add(new ListItem(monthname, val));
        }
    }

    public void LoadYear(DropDownList ddl, int start, int end)
    {
        string ddlval = "";
        string ddltxt = "";
        ddl.Items.Clear();
        ddl.Items.Add(new ListItem(Resources.CarInsurance.Year, "-1"));
        for (int _year = start; _year >= end; _year--)
        {
            ddlval = _year.ToString();
            ddltxt = _year.ToString();
            if (lblLangOption.Text == "1")
            {
                ddltxt = (_year + 543).ToString();
            }
            ddl.Items.Add(new ListItem(ddltxt, ddlval));
        }
    }

    public void LoadDOB()
    {
        int intStartYear = dateTimeNow.Year - 18;
        int intEndYear = dateTimeNow.Year - 90;

        LoadDate(ddlDriver1DOBDay);
        LoadMonth(ddlDriver1DOBMonth);
        LoadYear(ddlDriver1DOBYear, intStartYear, intEndYear);

        LoadDate(ddlDriver2DOBDay);
        LoadMonth(ddlDriver2DOBMonth);
        LoadYear(ddlDriver2DOBYear, intStartYear, intEndYear);
    }

    public void LoadCommanceDate()
    {
        CultureInfo ci = new CultureInfo("th-TH");
        if (lblLangOption.Text == "2")
        {
            ci = new CultureInfo("en-US");
        }
        DateTime dtNow = new DateTime();
        dtNow = dateTimeNow;
        for (int i = 2; i < 61; i++)
        {
            DateTime dtTemp = dtNow.AddDays(i);
            string strDate = dtTemp.Date.Day.ToString("00") + dtTemp.Date.Month.ToString("00") + dtTemp.Date.Year.ToString("0000");
            ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd/MMMM/yyyy", ci), strDate));
        }
        ddlCoverageComDate.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    public void LoadCommanceDate(DateTime StartDate)
    {
        CultureInfo ci = new CultureInfo("th-TH");
        if (lblLangOption.Text == "2")
        {
            ci = new CultureInfo("en-US");
        }
        DateTime dtNow = new DateTime();
        dtNow = StartDate.AddDays(-30);
        ddlCoverageComDate.Items.Clear();
        for (int i = 2; i < 61; i++)
        {
            DateTime dtTemp = dtNow.AddDays(i);
            string strDate = dtTemp.Date.Day.ToString("00") + dtTemp.Date.Month.ToString("00") + dtTemp.Date.Year.ToString("0000");
            ddlCoverageComDate.Items.Add(new ListItem(dtTemp.ToString("dd/MMMM/yyyy", ci), strDate));
        }
        ddlCoverageComDate.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    private void LoadCarYear()
    {
        int _yearCount = 10;
        ddlCarYear.Items.Clear();

        if (ddlInsuranceType.Text != "-1")
        {
            if (Convert.ToInt32(ddlInsuranceType.Text) >= 20)
            {
                _yearCount = 20;
            }
            int _startYear = dateTimeNow.Year - _yearCount;
            int _endYear = dateTimeNow.Year;
            for (int i = _endYear; i >= _startYear; i--)
            {
                if (lblLangOption.Text.Trim() != "1")
                {
                    ddlCarYear.Items.Add(new ListItem(i.ToString(), i.ToString()));
                }
                else
                {
                    ddlCarYear.Items.Add(new ListItem(i.ToString() + " - พ.ศ. " + (i + 543).ToString(), i.ToString()));
                }
            }
        }
        ddlCarYear.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    public void LoadCurrentInsurer()
    {
        DataTable dtPreInsurerComp = General.GetComboItem(Resources.DBTable.PreInsurer, Resources.DBTable.OrderByField, true);
        ddlCurrentInsurer.DataSource = dtPreInsurerComp;
        ddlCurrentInsurer.DataTextField = dtPreInsurerComp.Columns[0].ColumnName.ToString();
        ddlCurrentInsurer.DataValueField = dtPreInsurerComp.Columns[1].ColumnName.ToString();
        ddlCurrentInsurer.DataBind();
        ddlCurrentInsurer.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    }

    private void GetCarMakeList(string Year, DropDownList ddlList)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblMake");
        SortedList _spList = new SortedList();
        _spList.Add("@Year", Year);
        _dt = _db.GetDataTableBySP("sprocGetCarMakeTHListByYear", _spList);
        ddlList.Items.Clear();
        ddlList.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        if (_dt != null && _dt.Rows.Count > 0)
        {
            for (int i = 0; i < _dt.Rows.Count; i++)
            {
                ddlList.Items.Add(new ListItem(_dt.Rows[i][1].ToString(), _dt.Rows[i][0].ToString()));
            }
        }

        
        ddlList.Items.Insert(ddlList.Items.Count, new ListItem(Resources.CarInsurance.Other, "-2"));

        _dt = null;
        _db = null;
    }

    private void GetCarModelDescList(string CarMake, string Year, DropDownList ddlList)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelDesc");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@Year", Year);

        _dt = _db.GetDataTableBySP("sprocKawnaGetCarModelDescListByCarMakeCode", _spList);
        ddlList.Items.Clear();
        if (_dt != null && _dt.Rows.Count > 0)
        {
            ddlList.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
            ddlList.DataSource = _dt;
            ddlList.DataTextField = "CarModelDisplay";
            ddlList.DataValueField = "CarModelDesc";
            ddlList.DataBind();
           

            divOtherCar.Style.Add("display", "none");
            rfvOtherCarMake.Enabled = false;
            rfvOtherCarModel.Enabled = false;
            rfvOtherCarBody.Enabled = false;
            rfvCcCar.Enabled = false;
            revCcCar.Enabled = false;
            txtOtherCarMake.Text = "";
            txtOtherCarModel.Text = "";
            txtCcCar.Text = "";
            rfvSumInsured.Enabled = true;
        }
        else
        {
            
            ddlList.Items.Insert(ddlList.Items.Count, new ListItem(Resources.CarInsurance.Other, "-2"));
            divOtherCar.Style.Add("display", "");
            rfvOtherCarMake.Enabled = true;
            rfvOtherCarModel.Enabled = true;
            rfvOtherCarBody.Enabled = true;
            rfvCcCar.Enabled = true;
            revCcCar.Enabled = true;
            rfvSumInsured.Enabled = false;
            
        }

        _dt = null;
        _db = null;
    }

    private void GetCarMakeListOld(string Year, DropDownList ddlList)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblMake");
        SortedList _spList = new SortedList();
        _spList.Add("@Year", Year);
        _dt = _db.GetDataTableBySP("sprocGetCarMakeTHListByYear", _spList);
        ddlList.Items.Clear();
        ddlList.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
        if (_dt != null && _dt.Rows.Count > 0)
        {
            for (int i = 0; i < _dt.Rows.Count; i++)
            {
                ddlList.Items.Add(new ListItem(_dt.Rows[i][1].ToString(), _dt.Rows[i][0].ToString()));
            }
        }

        _dt = null;
        _db = null;
    }

    //private void GetCarModelDescListOld(string CarMake, string Year, DropDownList ddlList)
    //{
    //    MyDatabase _db = new MyDatabase();
    //    DataTable _dt = new DataTable("tblModelDesc");
    //    SortedList _spList = new SortedList();
    //    _spList.Add("@CarMake", CarMake);
    //    _spList.Add("@Year", Year);
    //    _dt = _db.GetDataTableBySP("sprocGetCarModelDescTHListByCarMakeCode", _spList);
    //    ddlList.Items.Clear();
    //    ddlModelBodyCCDoor.Items.Clear();
    //    ddlModelBodyCCDoor.Items.Add(new ListItem(Resources.CarInsurance.Select, "-1"));
    //    if (_dt != null && _dt.Rows.Count > 0)
    //    {
    //        for (int i = 0; i < _dt.Rows.Count; i++)
    //        {
    //            ddlList.Items.Add(new ListItem(_dt.Rows[i][0].ToString()));
    //        }
    //    }
    //    else
    //    {
    //        ddlList.Items.Insert(0, new ListItem(Resources.CarInsurance.Select, "-1"));
    //    }
    //    _dt = null;
    //    _db = null;
    //}

    private void GetCarModelSumInsuredAmountAndVehicleType(string CarMake, string CarModel, string Body, string CC, string Door, string Year, TextBox txtTextBox, Label lblLabel, Label lblLabelTwo)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelBody");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@CarModel", CarModel);
        _spList.Add("@Body", Body);
        _spList.Add("@CC", CC);
        _spList.Add("@Door", Door);
        _spList.Add("@Year", Year);
        _dt = _db.GetDataTableBySP("sprocGetCarModelSumInsuredAndVehicleTypeTHListByYear", _spList);
        if (_dt != null && _dt.Rows.Count > 0)
        {
            txtTextBox.Text = _dt.Rows[0][0].ToString();
            lblLabelTwo.Text = _dt.Rows[0][1].ToString();
            lblLabel.Text = Convert.ToInt32(txtTextBox.Text).ToString("#,000");
            //txtTextBox.Text = string.Format("{0:#,0}", _dt.Rows[0][0]);
        }
        else
        {
            txtTextBox.Text = "0";
            lblLabel.Text = "0";
        }
        txtTextBox.ReadOnly = true;
        _dt = null;
        _db = null;
    }

    private void GetCarModelGroupNo(string CarMake, string CarModel, string Body, string CC, string Door, TextBox txtTextBox)
    {
        MyDatabase _db = new MyDatabase();
        DataTable _dt = new DataTable("tblModelBody");
        SortedList _spList = new SortedList();
        _spList.Add("@CarMake", CarMake);
        _spList.Add("@CarModel", CarModel);
        _spList.Add("@Body", Body);
        _spList.Add("@CC", CC);
        _spList.Add("@Door", Door);
        _dt = _db.GetDataTableBySP("sprocGetCarModelGroupTH", _spList);

        if (_dt != null && _dt.Rows.Count > 0)
        {
            txtTextBox.Text = _dt.Rows[0][0].ToString();
        }
        else
        {
            txtGroupNo.Text = "-1";
        }
        txtTextBox.ReadOnly = true;
        _dt = null;
        _db = null;
    }

    private void setControlVisible()
    {
        if (ddlNamedDrivers.Enabled == false)
        {
            trNamedDriver.Visible = false;
        }
        else
        {
            trNamedDriver.Visible = true;
        }

        if (ddlDriver1DOBDay.Enabled == false)
        {
            trDriverFirstDOB.Visible = false;
        }
        else
        {
            trDriverFirstDOB.Visible = true;
        }

        if (ddlDriver2DOBDay.Enabled == false)
        {
            trDriverTwoDOB.Visible = false;
        }
        else
        {
            trDriverTwoDOB.Visible = true;
        }

        if (ddlCTPL.Enabled == false)
        {
            trIsCTPL.Visible = false;
        }
        else
        {
            trIsCTPL.Visible = true;
        }

        if (ddlModification.Enabled == false)
        {
            trModification.Visible = false;
        }
        else
        {
            trModification.Visible = true;
        }
        if (txtAccModAmount.Enabled == false)
        {
            trModificationAmount.Visible = false;
        }
        else
        {
            trModificationAmount.Visible = true;
        }
        if (ddlProvinceRegistration.Enabled == false)
        {
            trProvinceRegistration.Visible = false;
        }
        else
        {
            trProvinceRegistration.Visible = true;
        }
        if (ddlAnyClaim.Enabled == false)
        {
            trIsClaim.Visible = false;
        }
        else
        {
            trIsClaim.Visible = true;
        }
        if (ddlNCB.Enabled == false)
        {
            trNCB.Visible = false;
        }
        else
        {
            trNCB.Visible = true;
        }

        if (ddlDeduct.Enabled == false)
        {
            trDEC.Visible = false;
        }
        else
        {
            trDEC.Visible = true;
        }
    }

    #endregion

    #region Save & Update

    private bool Save(Int64 CompanyId)
    {
        Int64 _fleetcarresult = 0;
        Int64 _fleetpolicyresult = 0;

        FleetCarDetail _fleetcar = new FleetCarDetail();
        FleetCarDetailDB _fleetcardb = new FleetCarDetailDB();

        FleetCompany _fleetcompany = new FleetCompany();
        FleetCompanyDB _fleetcompanydb = new FleetCompanyDB();

        _fleetcar.CompanyId = Convert.ToInt64(txtCompanyId.Text.Trim());
        _fleetcar.FleetCarId = Convert.ToInt64(txtFleetCarId.Text.Trim()); 
        if (txtFleetCarId.Text != string.Empty && txtFleetCarId.Text != "0")
        {
            _fleetcar = _fleetcardb.GetCar(Convert.ToInt64(txtFleetCarId.Text.Trim()), CompanyId);
            if (lblRenewalStatus.Text == "1" || lblRenewalStatus.Text == "2")
            {
                _fleetcar.Info5 = "RENEWAL-UPDATE" + lblRenewalStatus.Text;
            }
            else
            {
                _fleetcar.Info5 = "UPDATE";
            }
        }
        else
        {
            if (lblRenewalStatus.Text == "1" || lblRenewalStatus.Text == "2")
            {
                _fleetcar.Info4 = "RENEWAL-NEW" + lblRenewalStatus.Text;
            }
            else
            {
                _fleetcar.Info4 = "NEW";
            }
        }

        if (_fleetcar == null)
        {
            _fleetcar = new FleetCarDetail();
            if (lblRenewalStatus.Text == "1" || lblRenewalStatus.Text == "2")
            {
                _fleetcar.Info4 = "RENEWAL-NEW" + lblRenewalStatus.Text;
            }
            else
            {
                _fleetcar.Info4 = "NEW";
            }
        }

        if (CompanyId > 0)
        {
            DataSet _dsFleetcompany = new DataSet();
            _dsFleetcompany = _fleetcompanydb.GetFleetCompany(CompanyId);
            if (_dsFleetcompany != null && _dsFleetcompany.Tables.Count > 0 && _dsFleetcompany.Tables[0].Rows.Count > 0)
            {
                _fleetcar.Info5 = _dsFleetcompany.Tables[0].Rows[0]["Email"].ToString();
                _fleetcar.Info6 = _dsFleetcompany.Tables[0].Rows[0]["ContactNo1"].ToString();
                _fleetcar.Info7 = _dsFleetcompany.Tables[0].Rows[0]["ContactPerson"].ToString();
               
                _fleetcar.Info9 = "M";
                _fleetcar.Info10 = General.GetUTCDateTimeToday().AddYears(-30).ToString("dd-MMM-yyyy"); //DateTime.Today
                _fleetcar.Info11 = "81";
                _fleetcar.Info12 = "";
                _fleetcar.Info13 = "1";
                _fleetcar.Info14 = "0";
                _fleetcar.Info15 = "";
            }
        }

        _fleetcar.ManufactYear = Convert.ToInt32(ddlCarYear.Text);

        if (Session[General.UserId] != "0")
        {
            _fleetcar.Info2 = Session[General.UserId].ToString();
            _fleetcar.Info3 = dateTimeNow.ToString();
        }

        _fleetcar.CarMakeName = ddlCarMake.Text;
        _fleetcar.MakeModelDesc = ddlCarMake.SelectedItem.Text + " " + ddlModelBodyCCDoor.SelectedItem.Text;

        bool IsOther = false;
        string[] _tempDesc = ddlModelBodyCCDoor.Text.Split(' ');
        if (_tempDesc.Length == 5)
        {
            _fleetcar.CarModelName = _tempDesc[0];
            _fleetcar.Body = _tempDesc[1];
            _fleetcar.CC = Convert.ToInt32(_tempDesc[2].Substring(0, _tempDesc[2].Length - 2));
            _fleetcar.Door = Convert.ToInt32(_tempDesc[3]);
        }
        else if (_tempDesc.Length == 6)
        {
            _fleetcar.CarModelName = _tempDesc[0] + " " + _tempDesc[1];
            _fleetcar.Body = _tempDesc[2];
            _fleetcar.CC = Convert.ToInt32(_tempDesc[3].Substring(0, _tempDesc[3].Length - 2));
            _fleetcar.Door = Convert.ToInt32(_tempDesc[4]);
        }
        else if (_tempDesc.Length == 7)
        {
            _fleetcar.CarModelName = _tempDesc[0] + " " + _tempDesc[1] + " " + _tempDesc[2];
            _fleetcar.Body = _tempDesc[3];
            _fleetcar.CC = Convert.ToInt32(_tempDesc[4].Substring(0, _tempDesc[4].Length - 2));
            _fleetcar.Door = Convert.ToInt32(_tempDesc[5]);
        }
        else if (ddlModelBodyCCDoor.Text == "-2")
        {
            // [Yui] @ 08/08/2013
            IsOther = true;
            _fleetcar.CarMakeName = txtOtherCarMake.Text.Trim();
            _fleetcar.CarModelName = txtOtherCarModel.Text.Trim();
            _fleetcar.Body = ddlOtherCarBody.Text;
            _fleetcar.CC = Convert.ToInt32(txtCcCar.Text.Trim());
            _fleetcar.Door = Convert.ToInt32(ddlOtherCarDoor.Text);

            _fleetcar.MakeModelDesc = txtOtherCarMake.Text.Trim() + " " + txtOtherCarModel.Text.Trim() + " " + ddlOtherCarBody.Text + " " + txtCcCar.Text.Trim() + " cc " + ddlOtherCarDoor.Text + " doors";
        }
        _fleetcar.GroupNo = Convert.ToInt32(txtGroupNo.Text);
        _fleetcar.Info2 = lblCarVehicleType.Text;


        if (lblCarVehicleType.Text == "PS" || lblCarVehicleType.Text == "SV" || lblCarVehicleType.Text == "")
        {
            _fleetcar.Info3 = ddlVehicleType.Text;
        }
        else if (lblCarVehicleType.Text == "LC")
        {
            if (ddlVehicleType.Text == "110")
            {
                _fleetcar.Info3 = "210";
            }
            else if (ddlVehicleType.Text == "120")
            {
                _fleetcar.Info3 = "220";
            }
        }
        else if (lblCarVehicleType.Text == "PU")
        {
            if (ddlVehicleType.Text == "110")
            {
                _fleetcar.Info3 = "320";
            }
            else if (ddlVehicleType.Text == "120")
            {
                _fleetcar.Info3 = "340"; //Disabled, No Packages
            }
        }
        _fleetcar.Status = true;
        _fleetcar.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
        _fleetcar.AgentId = Convert.ToInt64(txtAgentId.Text.Trim());
        _fleetcar.CurrentStep = 1;
        _fleetcar.TotalStep = 4;
        _fleetcar.Info1 = ddlCurrentInsurer.Text; 

        _fleetcarresult = _fleetcardb.Insert(_fleetcar);

        _fleetcardb.UpdateCarOther(_fleetcarresult, IsOther);
        _fleetcar = null;
        _fleetcardb = null;

        if (_fleetcarresult > 0)
        {
        }
        else
        {
            lblMessage.Text = "Insert error!";
        }
        if (_fleetcarresult > 0)
        {
            txtFleetCarId.Text = _fleetcarresult.ToString();
            //CAR POLICY DETAILS
            FleetCarPolicy _fleetcarpolicy = new FleetCarPolicy();
            FleetCarPolicyDB _fleetcarpolicydb = new FleetCarPolicyDB();
            Int64 _fleetcarId = Convert.ToInt64(txtFleetCarId.Text);

            Int64 _fleetcarpolicyid = 0;

            if (txtFleetCarPolicyId.Text != string.Empty && txtFleetCarPolicyId.Text != "0")
            {
                _fleetcarpolicyid = Convert.ToInt64(txtFleetCarPolicyId.Text);
                _fleetcarpolicy.FleetCarPolicyId = _fleetcarpolicyid;
                _fleetcarpolicy.Info5 = "UPDATE";
            }
            else
            {
                _fleetcarpolicy.Info4 = "NEW";
            }
            
            lblMessage.Text = "";
            if (Session[General.UserId] != null)
            {
                _fleetcarpolicy.Info2 = Session[General.UserId].ToString();
                _fleetcarpolicy.Info3 = dateTimeNow.ToString();
            }

            if (lblRenewalStatus.Text == "1" || lblRenewalStatus.Text == "2")
            {
                _fleetcarpolicy.Info6 = lblLastYearCarID.Text;
                _fleetcarpolicy.Info7 = lblLastYearRefNo.Text;
            }

            _fleetcarpolicy.FleetCarId = _fleetcarId;
            _fleetcarpolicy.CompanyId = Convert.ToInt64(txtCompanyId.Text.Trim()); 
            _fleetcarpolicy.InsuranceType = Convert.ToInt32(ddlInsuranceType.Text);
            _fleetcarpolicy.GarageType = Convert.ToInt32(ddlGarageType.Text);
            _fleetcarpolicy.VehicleType = Convert.ToInt32(ddlVehicleType.Text);
            _fleetcarpolicy.SumInsured = Convert.ToInt32(txtSumInsured.Text);
            _fleetcarpolicy.ProvinceRegistration = ddlProvinceRegistration.Text;
            _fleetcarpolicy.UseOfVehicle = "N/A";
            string strDate = ddlCoverageComDate.Text;
            int _iDay = Convert.ToInt32(strDate.Substring(0, 2));
            int _iMonth = Convert.ToInt32(strDate.Substring(2, 2));
            int _iYear = Convert.ToInt32(strDate.Substring(4, 4));
            _fleetcarpolicy.CoverageCommenceDate = new DateTime(_iYear, _iMonth, _iDay);
            _fleetcarpolicy.IsRedPlate = false;

            if (ddlModification.Text == "1")
            {
                _fleetcarpolicy.IsAddAccMod = true;
            }
            else
            {
                _fleetcarpolicy.IsAddAccMod = false;
            }

            if (_fleetcarpolicy.IsAddAccMod == true)
            {
                _fleetcarpolicy.AddAccModAmount = Convert.ToInt32(txtAccModAmount.Text);
            }
            else
            {
                _fleetcarpolicy.AddAccModAmount = 0;
            }
            _fleetcarpolicy.NCDPercent = Convert.ToInt32(ddlNCB.Text);
            if (ddlAnyClaim.Text == "1")
            {
                _fleetcarpolicy.IsClaimLastYear = true;
            }
            else
            {
                _fleetcarpolicy.IsClaimLastYear = false;
            }
            if (ddlCTPL.Text == "1")
            {
                _fleetcarpolicy.IsCTPL = true;
            }
            else
            {
                _fleetcarpolicy.IsCTPL = false;
            }

            if (ddlNamedDrivers.Text != "0")
            {
                _fleetcarpolicy.IsAddDriver = true;
                _fleetcarpolicy.NoOfDriver = Convert.ToInt16(ddlNamedDrivers.Text);
            }
            else
            {
                _fleetcarpolicy.IsAddDriver = false;
                _fleetcarpolicy.NoOfDriver = 0;
            }
            _fleetcarpolicy.Deductible = Convert.ToInt16(ddlDeduct.SelectedValue);
            _fleetcarpolicy.CurrentInsurer = ddlCurrentInsurer.SelectedItem.Text;
            _fleetcarpolicy.RefCEUserId = Convert.ToInt64(Session[General.UserId].ToString());
            _fleetcarpolicy.AgentId = Convert.ToInt64(txtAgentId.Text.Trim());
            _fleetcarpolicy.Status = true;
            _fleetcarpolicy.CurrentStep = 2;
            _fleetpolicyresult = _fleetcarpolicydb.Insert(_fleetcarpolicy);
            if (_fleetpolicyresult > 0)
            {
                txtFleetCarPolicyId.Text = _fleetpolicyresult.ToString();

                lblMessage.Text += "<br>Car policy saved successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Blue;
            }
            else
            {
                lblMessage.Text = "Car policy did not save successfully!";
                lblMessage.ForeColor = System.Drawing.Color.Red;
                return false;
            }

            FleetCarDriver _fleetcardriver = new FleetCarDriver();
            FleetCarDriverDB _fleetcardriverdb = new FleetCarDriverDB();

            if (ddlNamedDrivers.Text != "0")
            {
                int _drivercount = Convert.ToInt32(ddlNamedDrivers.Text);
                int _insertcount = 0;
                Int64 _deleteresult = _fleetcardriverdb.Delete(0, _fleetcarId, CompanyId, Convert.ToInt64(Session[CE.Global.General.UserId].ToString()));

                for (int i = 1; i <= _drivercount; i++)
                {
                    if (Session[CE.Global.General.UserId] != null)
                    {
                        _fleetcardriver.AgentId = Convert.ToInt64(txtAgentId.Text);
                    }
                    else
                    {
                        _fleetcardriver.AgentId = 0;
                    }
                    _fleetcardriver.RefCEUserId = Convert.ToInt64(Session[CE.Global.General.UserId].ToString());
                    _fleetcardriver.FleetCarId = Convert.ToInt64(txtFleetCarId.Text);
                    _fleetcardriver.CompanyId = Convert.ToInt64(txtCompanyId.Text);
                    if (i == 1)
                    {
                        _fleetcardriver.FleetCarDriverId = Convert.ToUInt32(txtDriverId1.Text);
                        DateTime _dtDriver1DOB = new DateTime(Convert.ToInt32(ddlDriver1DOBYear.Text), Convert.ToInt32(ddlDriver1DOBMonth.Text), Convert.ToInt32(ddlDriver1DOBDay.Text));
                        _fleetcardriver.DOB = _dtDriver1DOB;
                        _fleetcardriver.Status = true;
                    }
                    else if (i == 2)
                    {
                        _fleetcardriver.FleetCarDriverId = Convert.ToUInt32(txtDriverId2.Text); 
                        DateTime _dtDriver2DOB = new DateTime(Convert.ToInt32(ddlDriver2DOBYear.Text), Convert.ToInt32(ddlDriver2DOBMonth.Text), Convert.ToInt32(ddlDriver2DOBDay.Text));
                        _fleetcardriver.DOB = _dtDriver2DOB;
                        _fleetcardriver.Status = true;
                    }
                    if (_fleetcardriverdb.Insert(_fleetcardriver) > 0)
                    {
                        _insertcount++;
                    }
                }

                _fleetcardriverdb = null;
                _fleetcardriver = null;

                if (_insertcount == _drivercount)
                {
                    lblMessage.Text += "<br>All drivers are successfully saved!";
                    lblMessage.ForeColor = System.Drawing.Color.Blue;
                }
                else
                {
                    lblMessage.Text += "<br>All drivers are did not saved!";
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    return false;
                }
            }
            else
            {
                _fleetcardriverdb.Delete(0, _fleetcarId, CompanyId, Convert.ToInt64(Session[CE.Global.General.UserId].ToString()));
            }

            _fleetcarpolicy = null;
            _fleetcarpolicydb = null;
        }

        return _fleetpolicyresult > 0;
    }



 

    private bool CheckClaimValue()
    {
        bool ClaimValue = true;
        return ClaimValue;
    }

    #endregion


    private void GetSelectCarDetail(Int64 CompanyId, Int64 FleetCarId)
    {
        DataSet _dsFleetCar = new DataSet();
        MyDatabase _db = new MyDatabase();
        string _spName = "sprocFleetCarAndPolicyDetailSelectItemList";
        SortedList _spPara = new SortedList();
        _spPara.Add("@CompanyId", CompanyId);
        _spPara.Add("@FleetCarId", FleetCarId);
        _dsFleetCar = _db.GetDataSet(_spName, _spPara);
        if (_dsFleetCar != null && _dsFleetCar.Tables.Count > 0 && _dsFleetCar.Tables[0].Rows.Count > 0)
        {
            ddlInsuranceType.Text = _dsFleetCar.Tables[0].Rows[0]["InsuranceType"].ToString();
            ddlInsuranceType_SelectedIndexChanged(null, null);
            ddlGarageType.Text = _dsFleetCar.Tables[0].Rows[0]["GarageType"].ToString();
            LoadCarYear();
            ddlCarYear.Text = _dsFleetCar.Tables[0].Rows[0]["ManufactYear"].ToString();
            ddlCarYear_SelectedIndexChanged(null, null);
            ddlCarMake.Text = _dsFleetCar.Tables[0].Rows[0]["CarMake"].ToString();
            ddlCarMake_SelectedIndexChanged(null, null);
            string CarModelName = _dsFleetCar.Tables[0].Rows[0]["CarModelName"].ToString();
            string Body = _dsFleetCar.Tables[0].Rows[0]["Body"].ToString();
            string CC = _dsFleetCar.Tables[0].Rows[0]["CC"].ToString();
            string Door = _dsFleetCar.Tables[0].Rows[0]["Door"].ToString();
            string _tempDesc = CarModelName + " " + Body + " " + CC + "cc " + Door.ToString() + " doors";
            ddlModelBodyCCDoor.Text = _tempDesc;
            ddlModelBodyCCDoor_SelectedIndexChanged(null, null);
           
            if (_dsFleetCar.Tables[0].Rows[0]["IsAddDriver"].ToString() == "1")
            {
                ddlNamedDrivers.Text = _dsFleetCar.Tables[0].Rows[0]["NoOfDriver"].ToString();
            }
            else
            {
                ddlNamedDrivers.Text = "0";
            }
            ddlNamedDrivers_SelectedIndexChanged(null, null);
            ddlModification.Text = _dsFleetCar.Tables[0].Rows[0]["IsAddAccMod"].ToString();
            ddlModification_SelectedIndexChanged(null, null);
            txtAccModAmount.Text = _dsFleetCar.Tables[0].Rows[0]["AddAccModAmount"].ToString();
            ddlDeduct.Text = _dsFleetCar.Tables[0].Rows[0]["Deductible"].ToString();
            ddlProvinceRegistration.Text = _dsFleetCar.Tables[0].Rows[0]["ProvinceRegistration"].ToString();
            ddlAnyClaim.Text = _dsFleetCar.Tables[0].Rows[0]["IsClaimLastYear"].ToString();
            ddlNCB.Text = _dsFleetCar.Tables[0].Rows[0]["NCDPercent"].ToString();
        }
    }

}
